package com.spring.sunflower.anchor;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.AnchorDetailBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * Created by Kevin on 2021/6/21<br/>
 * <p>
 * Describe:<br/>
 */
public class AnchorBannerAdapter extends BannerAdapter<AnchorDetailBean.DatasBean.PhotoVOListBean, AnchorBannerAdapter.ImageHolder> {
    private Context context;

    public AnchorBannerAdapter(Context context, List<AnchorDetailBean.DatasBean.PhotoVOListBean> datas) {
        super(datas);
        this.context = context;
    }

    public void updateData(List<AnchorDetailBean.DatasBean.PhotoVOListBean> data) {
        //这里的代码自己发挥，比如如下的写法等等
        mDatas.clear();
        mDatas.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public AnchorBannerAdapter.ImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new ImageHolder(imageView);
    }

    @Override
    public void onBindView(AnchorBannerAdapter.ImageHolder holder, AnchorDetailBean.DatasBean.PhotoVOListBean data, int position, int size) {
        Glide.with(context)
                .load(data.getPhotoPath())
                .placeholder(R.drawable.ic_placeholder)
                .into(holder.imageView);
    }

    public class ImageHolder extends RecyclerView.ViewHolder {
        public ImageView imageView;

        public ImageHolder(@NonNull View view) {
            super(view);
            this.imageView = (ImageView) view;
        }
    }
}
